<script setup>
import { ref, onMounted } from "vue";

const active = ref(0);

// 定义 voteResults 和 hasFetchedResults
const voteResults = ref([]);
const hasFetchedResults = ref(false);

// 重置投票结果的方法
const resetVoteResults = () => {
    localStorage.removeItem("voteResults");
    localStorage.removeItem("hasFetchedResults");
    voteResults.value = [];
    hasFetchedResults.value = false;
    console.log("投票结果已重置");
};

// 在组件挂载时检查 sessionStorage
onMounted(() => {
    // 检查 sessionStorage 中是否存在标记
    const isInitialized = sessionStorage.getItem("isInitialized");
    if (!isInitialized) {
        // 如果是项目启动，执行重置逻辑
        resetVoteResults();
        // 设置标记，表示项目已经启动
        sessionStorage.setItem("isInitialized", "true");
    }
});
</script>

<template>
  <div>
    <nav class="header">基于区块链的电子投票系统</nav>
    <main>
      <router-view></router-view>
    </main>
    <van-tabbar route v-model="active" active-color="#ee742f">
      <van-tabbar-item to="/" icon="gem-o">分发票权</van-tabbar-item>
      <van-tabbar-item to="/account" icon="balance-list-o">账户信息</van-tabbar-item>
      <van-tabbar-item to="/board" icon="orders-o">投票看板</van-tabbar-item>
    </van-tabbar>
  </div>
</template>

<style lang="less" scoped>
.header {
  height: 44px;
  background-color: #e3770a;
  color: #fff;
  text-align: center;
  line-height: 44px;
}
</style>

<style lang="less">
html,
body {
  margin: 0;
  padding: 0;
  overflow: hidden;
}
</style>